package com.dingwei.lesyndrome.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.bean.AddressListBean;
import com.dingwei.lesyndrome.bean.GamCircleTypeBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/3/9.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class AddressListAdapter extends RecyclerArrayAdapter<AddressListBean.DataBean> {

    public interface addressInterFace {
        void delete(int position);
    }

    private addressInterFace addressInterfaceListener;

    public void setOnAddressInterfaceListener(addressInterFace listener) {
        addressInterfaceListener = listener;

    }


    public AddressListAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new AddressListHolder(parent);
    }


    public class AddressListHolder extends BaseViewHolder<AddressListBean.DataBean> {


        @Bind(R.id.tv_address)
        TextView tvAddress;
        @Bind(R.id.img_delete)
        ImageView imgDelete;

        public AddressListHolder(ViewGroup parent) {
            super(parent, R.layout.item_address);
            ButterKnife.bind(this, itemView);


        }

        @Override
        public void setData(AddressListBean.DataBean data) {
            super.setData(data);
            tvAddress.setText(data.name);
            imgDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (addressInterfaceListener!=null){
                        addressInterfaceListener.delete(getDataPosition());
                    }
                }
            });
        }
    }
}
